import 'dart:convert';
import '../model/cartmodellist.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
//import 'package:flutter_banner_swiper/flutter_banner_swiper.dart';
import 'package:dio/dio.dart';

//import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_easyrefresh/material_header.dart';
import 'package:flutter_easyrefresh/material_footer.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
//import './home_swiper1.dart';
//import 'dart:convert';
import '../config/api.dart';
import '../model/cartmodellist.dart';
class HomeSwiper extends StatefulWidget {
  HomeSwiper({Key key}) : super(key: key);

  @override
  _HomeSwiperState createState() => _HomeSwiperState();
}

class _HomeSwiperState extends State<HomeSwiper> {
  String mas2="[]";
  String mas3;
  String c1;
  // List m1=[];
  // List m2=[];
  List g3=[];
  List g2=[{ "id": 9,
            "goodsname": "夏季超薄文胸无海绵薄款内衣聚拢大胸显小大码女士无钢圈蕾丝胸罩",
            "price": 48,
            "maxpeople": 44,
            "url": "http://dbyxs.xyz:3005/uploads/7347139ef2b416ee36945a0d874d11e7,http://dbyxs.xyz:3005/uploads/2d010131df0f346f3ecbe844185f9f3b,http://dbyxs.xyz:3005/uploads/d12b652a67d8fb835c322dd851a9d77d",
            "status": "0",
            "banelurl": "http://dbyxs.xyz:3005/uploads/871a093a0a23d9dee4948b93e1006067,http://dbyxs.xyz:3005/uploads/97ad53a066062ad9f1717dda5c7cedc7,http://dbyxs.xyz:3005/uploads/061fc961266eb0db4338b25b8c03ed2e,http://dbyxs.xyz:3005/uploads/08773c8a3f9aa0c45737a4650261c1f6,http://dbyxs.xyz:3005/uploads/a023370edf522f39bffe8bde679c5799",
            "type": 3,
            "gender": "1",
            "dates": "000000000000000",
            "commod": 99,
            "time": null,
            "tit": "黑色,白色,紫色",
            "titxx": "36A,36B,36D"},{
               
            "id": 26,
            "goodsname": "夏装2020新款韩版时尚美背小吊带背心女夏内搭打底衫宽松小衫气质",
            "price": 48,
            "maxpeople": 0,
            "url": "http://dbyxs.xyz:3005/uploads/d8e3093bce385b00b61ac3d73ceb3dac,",
            "status": "0",
            "banelurl": "http://dbyxs.xyz:3005/uploads/84c13e182800e4d9362878e420b723cc,",
            "type": 2,
            "gender": "1",
            "dates": "",
            "commod": 100,
            "time": "2020-06-12T06:26:51.000Z",
            "tit": "灰色,红色,白色",
            "titxx": ""
        
            },{
              "id": 27,
            "goodsname": "歆觅吊带背心女罩杯一体式带胸垫免穿文胸内衣小内搭抹胸打底黑色",
            "price": 39,
            "maxpeople": 0,
            "url": "http://dbyxs.xyz:3005/uploads/6dd72fcb34cbada163042dd8d2be200c,http://dbyxs.xyz:3005/uploads/21d083f3a15c22556ce8a75983aae596,http://dbyxs.xyz:3005/uploads/62d2a947311d3d1489e26df18554ec00,http://dbyxs.xyz:3005/uploads/1300ef93fea74d81baf5f81a9b129485,http://dbyxs.xyz:3005/uploads/bcabcaab63f17391860521d4172437c1,",
            "status": "0",
            "banelurl": "http://dbyxs.xyz:3005/uploads/f19427dd51a28b95d94725c2ba5970e2,http://dbyxs.xyz:3005/uploads/80385fd59ae29b95ede0cd374cf2960b,http://dbyxs.xyz:3005/uploads/feef89c5da04701db56766545e7382c5,",
            "type": 3,
            "gender": "1",
            "dates": "",
            "commod": 98,
            "time": "2020-06-12T07:17:10.000Z",
            "tit": "白色,红色,灰色",
            "titxx": "M,L,XXL"
            },{
               "id": 58,
            "goodsname": "真丝内衣无钢圈薄款小胸聚拢细肩带无痕胸罩100%桑蚕丝文胸女夏季",
            "price": 109,
            "maxpeople": 0,
            "url": "http://dbyxs.xyz:3005/uploads/53a821a7f3010bea7d4aa97ef6d134a2,http://dbyxs.xyz:3005/uploads/3e95177dfea1fbd1da310a3f40b40f6c,http://dbyxs.xyz:3005/uploads/703952c6da6ec08629d52951c186878a,http://dbyxs.xyz:3005/uploads/c6fde781ad15b8d13c8c300314ba36fe,http://dbyxs.xyz:3005/uploads/5d578d78c1f0994f26bdcd2e23cd0edd,",
            "status": "0",
            "banelurl": "http://dbyxs.xyz:3005/uploads/1c81759f70bc9f1bfd680631f9a44c17,http://dbyxs.xyz:3005/uploads/503ec3fc5fe1bf2ca884d60c213deb65,http://dbyxs.xyz:3005/uploads/6cb186d3ed1dae6841ff691e9317cdb2,http://dbyxs.xyz:3005/uploads/d38ed274f813224d0902f3dcd418cfe9,http://dbyxs.xyz:3005/uploads/1c9b8f332c300dbef8a10cbd3d595df9,",
            "type": 3,
            "gender": "1",
            "dates": "",
            "commod": 100,
            "time": "2020-06-29T12:55:34.000Z",
            "tit": "肤色,黑色,粉色",
            "titxx": "70A,70B,75A,75B"
            }];
  Map<String, dynamic> goods;
  bool lY=false;
  //发起数据请求
 List data;
  void getGoods(v) async {
   // this.ly=true;
    getlists(v).then((value) => {
       this.lY=true,
       add(1)
      // data=value.data,
    //  if(value.data=null){
    //    this.lY=false
    //  }else{
    //    add(1),
    //    this.goods=value.data,
    //   this.lY=true,
    //   add(1)
    //  }
      // setState((){
      //  this.lY=true;
      //   this.goods=value.data;
       
      // //  print(value.data['message'][0]['url'].split(',')[0]);
      // //  print(this.goods['message']);
      // })
    // print(value.data);
    });
   
  }
 // get json => null;
 //获取热销商品
 saveplace()async{
   SharedPreferences prefs=await SharedPreferences.getInstance();
 } 
 //获取商品大类
//   save()async{
//     SharedPreferences prefs=await SharedPreferences.getInstance();
//   //  mas3=this.mas['message'].toString();
//   //  mas2=prefs.getString('cartinfo');
//  // jsonDecode(this.mas['message'].toString());
//  //print(this.mas['message'].length);
// //  g3=await json.decode(prefs.getString('goodslist'))|[];
// //  g3.forEach((item) {
// //    if(item['type']==3){
// //      g2.add(item);
// //    }
// //  });
// // //  g2.length=4;
// // //  print(g2);
// //  prefs.setString('four', json.encode(g2));
//  if(json.decode(prefs.getString('f')).length>0){

//  setState(() {

//    this.flag=true;
//      //  m1=json.decode(prefs.getString('f'));
//     });
//  //m1=json.decode(prefs.getString('f'));
//     //return m1;
//  }else{

//     setState(() {
//         mas3= json.encode(this.mas['message']);
//     prefs.setString('f',mas3 );
//      //  m1=json.decode(prefs.getString('f'));
//     });
//    // return m1;
//  }
//  //json.decode(prefs.getString('g')).length>0 
//  // m1.addAll(jsonDecode(prefs.getString('f'))); 
// // List<Map> tempList= (temp as List).cast();
//    print('我是持久化存储${m1.length}');
//    //print('我是持久化存储${jsonDecode(prefs.getString('v')).length}');
    
//    // print('我是持久化存储1${prefs.remove('f')}');
//    // print('我是持久化存储${json.decode(prefs.getString('f')).length}');
   
//   }
  
  sav() async{
   
 
  //    SharedPreferences prefs=await SharedPreferences.getInstance();
  //  // print('我是长度${json.decode(prefs.getString('g'))>0}');
  //   //  print(prefs.getString('g'));
  //      if(json.decode(prefs.getString('g')).length>0){
         
  //   // setState(() {
  //   //    mas2=json.encode(this.goods['message']);
  //   //  prefs.setString('g', mas2);
  //   //    m2=json.decode(prefs.getString('g'));
  //   // });
  //   // return m2;
  //    setState(() {
  //      m2=json.decode(prefs.getString('g'));
  //     // this.lY=true;
  //      print(m2[0]['url'].split(',')[0]);
  //    });
  //    return m2;
  //  }else if(false){
  //    mas2=json.encode(this.goods['message']);
  //    prefs.setString('g', mas2);
  //   setState(() {
  //      m2=json.decode(prefs.getString('g'));
  //   });
  //   return m2;
  //  }
  }
  
  //加载更多key 必填
  EasyRefreshController _controller;
  // GlobalKey<EasyRefreshState> _easyRefreshKey = new GlobalKey<EasyRefreshState>();
  GlobalKey _headerKey = GlobalKey();

  GlobalKey _footerKey = GlobalKey();
  ScrollController _scrollController = new ScrollController();
  int a=5;
  List<Map> c = [
    {
      "id": 0,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 1,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 2,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 3,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 4,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 5,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 7,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 8,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 9,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 10,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 11,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 12,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 13,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 14,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 15,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 16,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 17,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
    {
      "id": 18,
      "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    },
  ];
  List imglist ;
  // [
  //   {
  //     "url": 'http://dbyxs.xyz:3005/uploads/95f68826d349641b3fe48843316363a2',
  //     "id": 2
  //   },
  //   {
  //     "url": 'http://dbyxs.xyz:3005/uploads/3bdb1804f927444353a1dc3c0cf82686',
  //     "id": 3
  //   },
  // ];
  List imgs=[
    {
  "url": 'http://dbyxs.xyz:3005/uploads/95f68826d349641b3fe48843316363a2',
  "id": 2
},
{
  "url": 'http://dbyxs.xyz:3005/uploads/3bdb1804f927444353a1dc3c0cf82686',
  "id": 3},
   {
  "url": 'http://dbyxs.xyz:3005/uploads/95f68826d349641b3fe48843316363a2',
  "id": 2
},
{
  "url": 'http://dbyxs.xyz:3005/uploads/3bdb1804f927444353a1dc3c0cf82686',
  "id": 3},
  ];
  Map<String, dynamic> map;
  Map<String, dynamic> mas;
  bool flag=false;
  bool ly=false;
  
  //List<Map>map=[];
  void getList() async {
    var url = 'http://dbyxs.xyz:3005/tion/get';
    try {
      Response response;
      Dio dio = new Dio();
      var c = {"sidel": "0"};
      dio.options.contentType = "application/x-www-form-urlencoded";
      // Options options = Options(headers: {HttpHeaders.acceptHeader:"accept: application/x-www-form-urlencoded"});
      // Options options.contentType= ContentType.parse('application/x-www-form-urlencoded');
      response = await Dio().post(
        url,
        data: c,
      );
      //  print(response.data.toString());
      setState(() {
        add(1);
        map = response.data;
        // map=json.decode(response.data.toString());
        // print('${this.map}没有数据');
        print(this.map.length);
      });
      // return response.data;
    } catch (e) {
      print('${e}错误');
    }
    try {
      Response response;
      Dio dio = new Dio();
      var c = {"sidel": "1"};
      dio.options.contentType = "application/x-www-form-urlencoded";
      // Options options = Options(headers: {HttpHeaders.acceptHeader:"accept: application/x-www-form-urlencoded"});
      // Options options.contentType= ContentType.parse('application/x-www-form-urlencoded');
      response = await Dio().post(
        url,
        data: c,
      );
      //  print(response.data.toString());
      setState(() {
        mas = response.data;
      
        this.flag=true;
      });
      // return response.data;
    } catch (e) {
      print('${e}错误');
    }
  }
  bool y1=false;
var h=1;
  @override
  void initState() {
    super.initState();
   
   //this.save();
   this.getGoods(h);
    this.sav();
   setState((){
     add(1);
       getlist();
    this.getList();
   });
   getTionlist();
    //add(1);
    print('m1没有数据吗${m1}');
    new Duration();
  }
 void getTionlist()async{
   getTion().then((value) => {
     print(value),
     if(value.data['err_code']==200){
       setState((){
         var c=json.encode(value.data['message']);
        // this.imglist.add(value.data['message']);
         print(c);
         this.imglist=json.decode(c);
         //print(value.data['message'][0]['img']);
       })
     }
   });
  }
List <Map>mas1=[
        
        {
            "id": 2,
            "title": "优质美食",
            "img": "http://dbyxs.xyz:3005/uploads/2628a89a7bc7b9f18dc65529fed48e62",
            "goodsId": 0,
            "detail": 0,
            "sidel": 1,
            "type": 4,
            "flag": ""
        },
        {
            "id": 3,
            "title": "土货鲜食",
            "img": "http://dbyxs.xyz:3005/uploads/37e08caa53a08d45e89a3939eb02d0e8",
            "goodsId": 0,
            "detail": 0,
            "sidel": 1,
            "type": 9,
            "flag": ""
        },
        {
            "id": 4,
            "title": "会员中心",
            "img": "http://dbyxs.xyz:3005/uploads/e1e4c53fb01e1e279eb0b31e0a77a487",
            "goodsId": 0,
            "detail": 0,
            "sidel": 1,
            "type": 1,
            "flag": ""
        },
        {
            "id": 5,
            "title": "造点新货",
            "img": "http://dbyxs.xyz:3005/uploads/01239978a5dfc88de9b4acafaad5b034",
            "goodsId": 0,
            "detail": 0,
            "sidel": 1,
            "type": 2,
            "flag": ""
        },
        {
            "id": 6,
            "title": "美妆馆",
            "img": "http://dbyxs.xyz:3005/uploads/dbf1f55401cdb3f4cc52f8d6e10babe8",
            "goodsId": 0,
            "detail": 0,
            "sidel": 1,
            "type": 12,
            "flag": ""
        },
        {
            "id": 7,
            "title": "时尚潮流",
            "img": "http://dbyxs.xyz:3005/uploads/aaf3750a394f7a2f9656391ab00478cc",
            "goodsId": 0,
            "detail": 0,
            "sidel": 1,
            "type": 2,
            "flag": ""
        },
        {
            "id": 8,
            "title": "分类",
            "img": "http://dbyxs.xyz:3005/uploads/69ca0c1d79b9eadae9ad1d819e895fd6",
            "goodsId": 0,
            "detail": 0,
            "sidel": 1,
            "type": 1,
            "flag": ""
        },
        {
            "id": 11,
            "title": "母婴",
            "img": "http://dbyxs.xyz:3005/uploads/d7488525fd62fe82a9e559b1e8ddcfd7",
            "goodsId": 0,
            "detail": 0,
            "sidel": 1,
            "type": 3,
            "flag": ""
        },
        {
            "id": 12,
            "title": "医药",
            "img": "http://dbyxs.xyz:3005/uploads/11a74530bba1304db95fe7395fb65a2c",
            "goodsId": 0,
            "detail": 0,
            "sidel": 1,
            "type": 10,
            "flag": ""
        },
        {
            "id": 13,
            "title": "日用",
            "img": "http://dbyxs.xyz:3005/uploads/c310c258133c0b5ff4a767cf3f3f77ef",
            "goodsId": 0,
            "detail": 0,
            "sidel": 1,
            "type": 11,
            "flag": ""
        }
    ]
;
  List<Widget> _getbanel()  {
    // SharedPreferences prefs=await SharedPreferences.getInstance();
   // print(this.m1);
    List<Widget> list = new List();
    //this.mas['message'].length<1
    //this.save();
    if(!this.flag){
          for (var i = 0; i < 10; i++) {
      list.add(InkWell(
          onTap: () {
            print('我是什么类型${this.mas1[i]}');
            Navigator.pushNamed(context, '/goodslist',
                arguments: {"id": this.mas1[i]['type']});
            // Navigator.pushNamed(context, '/goodslist',arguments: {"id":this.mas['message'][i]['type']});
            // print(mas['message'][i]['type']);
          },
          child:
         // Image.network('http://dbyxs.xyz:3005/uploads/3bdb1804f927444353a1dc3c0cf82686')
              Image.network('${this.mas1[i]['img']}')
              ));
    }
    return list.toList(); 
    }else{
      for (var i = 0; i < 10; i++) {
      list.add(InkWell(
          onTap: () {
             print('我是什么类型${this.mas1[i]}');
            Navigator.pushNamed(context, '/goodslist',
                arguments: {"id": this.mas['message'][i]});
            // Navigator.pushNamed(context, '/goodslist',arguments: {"id":this.mas['message'][i]['type']});
            // print(mas['message'][i]['type']);
          },
          child:
              Image.network(mas == null ? '' : '${mas['message'][i]['img']}')));
    }
    return list.toList();
    }
  }
Widget gl(BuildContext context,int index){
  return 
  // Container(
  //   width: ScreenUtil().setWidth(188),
  //   child: 
    InkWell(
                   child:  Container(
                    decoration: BoxDecoration(
                      border: Border.all(width:ScreenUtil().setWidth(1),color:Colors.black38)
                    ),
                    width: ScreenUtil().setWidth(188),
                   height: ScreenUtil().setHeight(250),
                    child: Column(
                      children: <Widget>[
                        Container(
                          width: ScreenUtil().setWidth(186),
                          height: ScreenUtil().setHeight(150),
                          //http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e
                          child: Image.network('http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e',fit:BoxFit.cover),
                        ),
                        Center(
                          child: Text('时尚女孩',style: TextStyle(fontSize: 14, ),),
                        ),
                        Center(
                          child: Text('月销10000件',style: TextStyle(fontSize:12,color:Colors.black38),),
                        )
                      ],
                    ),
                    //ListView.builder(itemBuilder: _gl,itemCount:4)
                  ),
                 );
  //);
}

  @override
  Widget build(BuildContext context) {
  // add(1);
    // getList();
    
    return
        //  SingleChildScrollView(
        //    padding: EdgeInsets.all(0),
        //    child:
        // Column(
        //   children: <Widget>[
        //商品轮播图区域
        //  Container( 
        // height: 700,
        //   child:
        EasyRefresh(
          controller: _controller,
      child: ListView(
        children: <Widget>[
          Container(
            padding: EdgeInsets.all(5),
            decoration: BoxDecoration(
                //  border: ,
                //color: Colors.red,
                borderRadius: BorderRadius.circular(25)),
            child: AspectRatio(
              aspectRatio: 16 / 6,
              child: Swiper(
                itemBuilder: (BuildContext context, int index) {
                  return ClipRRect(
                    borderRadius: BorderRadius.circular(10),
                    child:
                        //Image.network(imglist[index]['url'], fit: BoxFit.cover)
                        Image.network(
                         imglist==null?imgs[index]['url']: imglist[index]['img'],
                            //  map == null
                            //     ? imgs[index]['url']
                            //     : map['message'][index]['img'],
                            fit: BoxFit.cover),
                  );
                },
                itemCount: 4,
                onTap: (index) {
                  getList();
                  Navigator.pushNamed(context, '/homedetail',
                      arguments: {"id": this.imglist[index]['id']});
                  print('点击了${this.imglist[index]['id']}');
                },
                pagination: SwiperPagination(
                    builder: DotSwiperPaginationBuilder(
                  color: Colors.white,
                  //  color: Color.fromRGBO(200, 200, 200, 0.5),
                  size: 8.0,
                  activeSize: 10.0,
                )),
                // control: SwiperControl(
                //     color: Theme.of(context).primaryColor.withOpacity(.5)
                //     ),
                loop: true,
                autoplay: true,
              ),
            ),
          ),
          //轮播图区域
          // Container(
          //   padding: EdgeInsets.all(10),
          //   color: Colors.pink[100],
          //   child: AspectRatio(
          //       aspectRatio: 16 / 6,
          //       // child: ClipRRect(
          //       // borderRadius: BorderRadius.circular(10),
          //       child: BannerSwiper(
          //         //width  和 height 是图片的高宽比  不用传具体的高宽   必传
          //         height: 108,
          //         width: 54,
          //         //轮播图数目 必传
          //         length: this.imglist.length,

          //         //轮播的item  widget 必传
          //         getwidget: (index) {
          //           return new GestureDetector(
          //               child: ClipRRect(
          //                 borderRadius: BorderRadius.circular(10),
          //                 child: Image.network(
          //                   this.imglist[index % imglist.length]['url'],
          //                   fit: BoxFit.cover,
          //                 ),
          //               ),
          //               onTap: () {
          //                 Navigator.pushNamed(context, '/homedetail', arguments: {
          //                   "id": this.imglist[index % imglist.length]['id']
          //                 });
          //                 print(this.imglist[index % imglist.length]['id']);
          //                 //点击后todo
          //               });
          //         },
          //       )
          //       // )
          //       ),
          // ),
          //九宫格区域
          Container(
              padding: EdgeInsets.all(10),
              //  margin: EdgeInsets.only(left:10),
              color: Colors.white,
              child: AspectRatio(
                  aspectRatio: 16 / 6,
                  child: GridView.count(
                      crossAxisSpacing: 16.0,
                      mainAxisSpacing: 16.0,
                      crossAxisCount: 5,
                      children: _getbanel()))),
          //热销商品区域
          Container(
            width: double.infinity,
            //width: ScreenUtil().setWidth(750),
            child: Column(
              children: <Widget>[
                Row(
                  children: <Widget>[
                    SizedBox( width: 10,),
                    Text('热销商品',style: TextStyle(fontSize:16, fontWeight: FontWeight.w600 ),),
                    SizedBox( width: 10,),
                    Text('时尚 女性 生活',style: TextStyle(fontSize: 12,color: Colors.black38),)
                  ],
                ),
                Container(
                  width: ScreenUtil().setWidth(750),
              child: 
            Card(
              
              child:   Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                 Container(
                    padding: EdgeInsets.all(2),
                   width: ScreenUtil().setWidth(188),
                   child:
                   InkWell(
                     onTap: (){
                        Navigator.of(context).pushNamed('/goodscommodity',arguments: {"id":g2[0]});
                     },
                   child:  Container(
                    decoration: BoxDecoration(
                      //border: Border.all(width:ScreenUtil().setWidth(1),color:Colors.black38)
                    ),
                    width: ScreenUtil().setWidth(188),
                   height: ScreenUtil().setHeight(250),
                    child: Column(
                      children: <Widget>[
                        Container(
                          width: ScreenUtil().setWidth(186),
                          height: ScreenUtil().setHeight(150),
                          //http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e g2.length<=0
                          child: 
                          //Image.network('http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e',fit:BoxFit.cover),
                          Image.network('${g2.length<=0?'':g2[0]['url'].split(',')[0]}',fit:BoxFit.cover),
                        ),
                        Center(
                          child: Text('${g2.length<=0?'':g2[0]['goodsname']}',style: TextStyle(fontSize: 14, ),maxLines: 1, overflow: TextOverflow.ellipsis,),
                        ),
                        SizedBox(height:10),
                        Center(
                          child: Text('月销10000件',style: TextStyle(fontSize:12,color:Colors.black38),),
                        )
                      ],
                    ),
                    //ListView.builder(itemBuilder: _gl,itemCount:4)
                  ),
                 ),
                 ),
                  Container(
                     padding: EdgeInsets.all(2),
                   width: ScreenUtil().setWidth(180),
                   child:
                   InkWell(
                     onTap: (){
                        Navigator.of(context).pushNamed('/goodscommodity',arguments: {"id":g2[1]});
                     },
                   child:  Container(
                    decoration: BoxDecoration(
                     // border: Border.all(width:ScreenUtil().setWidth(1),color:Colors.black38)
                    ),
                    width: ScreenUtil().setWidth(180),
                   height: ScreenUtil().setHeight(250),
                    child: Column(
                      children: <Widget>[
                        Container(
                          width: ScreenUtil().setWidth(180),
                          height: ScreenUtil().setHeight(150),
                          //http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e
                          child: Image.network('${g2.length<=0?'':g2[1]['url'].split(',')[0]}',fit:BoxFit.cover),
                        ),
                        Center(
                          child: Text('${g2.length<=0?'':g2[1]['goodsname']}',style: TextStyle(fontSize: 14, ),maxLines: 1, overflow: TextOverflow.ellipsis,),
                        ),
                        SizedBox(height:10),
                        Center(
                          child: Text('月销10000件',style: TextStyle(fontSize:12,color:Colors.black38),),
                        )
                      ],
                    ),
                    //ListView.builder(itemBuilder: _gl,itemCount:4)
                  ),
                 ),
                 ),
                  Container(
                     padding: EdgeInsets.all(2),
                   width: ScreenUtil().setWidth(180),
                   child:
                   InkWell(
                     onTap: (){
                        Navigator.of(context).pushNamed('/goodscommodity',arguments: {"id":g2[2]});
                     },
                   child:  Container(
                    decoration: BoxDecoration(
                     // border: Border.all(width:ScreenUtil().setWidth(1),color:Colors.black38)
                    ),
                    width: ScreenUtil().setWidth(180),
                   height: ScreenUtil().setHeight(250),
                    child: Column(
                      children: <Widget>[
                        Container(
                          width: ScreenUtil().setWidth(186),
                          height: ScreenUtil().setHeight(150),
                          //http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e
                          child: Image.network('${g2.length<=0?'':g2[2]['url'].split(',')[0]}',fit:BoxFit.cover),
                        ),
                        Center(
                          child: Text('${g2.length<=0?'':g2[2]['goodsname']}',style: TextStyle(fontSize: 14, ),maxLines: 1, overflow: TextOverflow.ellipsis,),
                        ),
                        SizedBox(height:10),
                        Center(
                          child: Text('月销10000件',style: TextStyle(fontSize:12,color:Colors.black38),),
                        )
                      ],
                    ),
                    //ListView.builder(itemBuilder: _gl,itemCount:4)
                  ),
                 ),
                 ),
                  Container(
                   width: ScreenUtil().setWidth(180),
                   padding: EdgeInsets.all(2),
                   child:
                   InkWell(
                     onTap: (){
                       Navigator.of(context).pushNamed('/goodscommodity',arguments: {"id":g2[3]});
                     },
                   child:  Container(
                    decoration: BoxDecoration(
                      //border: Border.all(width:ScreenUtil().setWidth(1),color:Colors.black38)
                    ),
                    width: ScreenUtil().setWidth(180),
                   height: ScreenUtil().setHeight(250),
                    child: Column(
                      children: <Widget>[
                        Container(
                          width: ScreenUtil().setWidth(186),
                          height: ScreenUtil().setHeight(150),
                          //http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e
                          child: Image.network('${g2.length<=0?'':g2[3]['url'].split(',')[0]}',fit:BoxFit.cover),
                        ),
                        Center(
                          child: Text('${g2.length<=0?'':g2[3]['goodsname']}',style: TextStyle(fontSize: 14, ),maxLines: 1, overflow: TextOverflow.ellipsis,),
                        ),
                        SizedBox(height:10),
                        Center(
                          child: Text('月销10000件',style: TextStyle(fontSize:12,color:Colors.black38),),
                        )
                      ],
                    ),
                    //ListView.builder(itemBuilder: _gl,itemCount:4)
                  ),
                 ),
                 ),
                ],
              ),
            )
            ),
              ],
            )
          ),
          //商品瀑布流区域
         // HomeSwiper1()
          Container(
            child: Pub()
            
            // child: ListView.builder(itemBuilder: _getlist,itemCount: c.length,),
          ),
        ],
      ),
      header: MaterialHeader(
      //  key: _headerKey,
       // enableHapticFeedback: true
       // backgroundColor: Colors.red,
        //valueColor: 
        //moreInfoColor:Colors.pink,
      ),
      footer: MaterialFooter(
       // key: _footerKey,
        displacement:40.0,
       enableInfiniteLoad: false,
       enableHapticFeedback:true,
        completeDuration : const Duration(seconds: 1),
       
      ),
      
      onRefresh: () async {
        
         print('我是上拉刷新');
       setState(() {
         h++;
         add(h);
          // this.getGoods(h);
          a=5;
       });
      },
      onLoad: () async {
       // c.length=5;
    //       c.add({
    //   "id": 19,
    //   "img": 'http://dbyxs.xyz:3005/uploads/fae4e814a5d9510d10277ff78ea6dc12'
    // },);
        setState(() {
          if(m1.length/5==a/5){
          a=  m1.length;
          pub1(a);
          return a;
          }else{
             a+=5;
              pub1(a);
          }
         // c.length=a;
        });
       print('我是下拉加载${c}');
      },
    );
    //   )
    // ],
    // );
    // );
  }
}
